package com.siyougame.business.service.inspectItemImg;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.siyougame.business.controller.admin.inspectItemImg.vo.*;
import com.siyougame.business.dal.dataobject.inspectItemImg.InspectItemImgDO;
import com.siyougame.common.pojo.PageResult;

import com.siyougame.business.convert.inspectItemImg.InspectItemImgConvert;
import com.siyougame.business.dal.mysql.inspectItemImg.InspectItemImgMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import static com.siyougame.common.exception.util.ServiceExceptionUtil.exception;
import static com.siyougame.business.enums.ErrorCodeConstants.*;

/**
 * 检查记录明细附件 Service 实现类
 *
 * @author ${table.author}
 */
@Service
@Validated
public class InspectItemImgServiceImpl extends ServiceImpl<InspectItemImgMapper,  InspectItemImgDO> implements InspectItemImgService {

    @Resource
    private InspectItemImgMapper inspectItemImgMapper;

    @Override
    public Long createInspectItemImg(InspectItemImgCreateReqVO createReqVO) {
        // 插入
        InspectItemImgDO inspectItemImg = InspectItemImgConvert.INSTANCE.convert(createReqVO);
        inspectItemImgMapper.insert(inspectItemImg);
        // 返回
        return inspectItemImg.getId();
    }

    @Override
    public void updateInspectItemImg(InspectItemImgUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateInspectItemImgExists(updateReqVO.getId());
        // 更新
        InspectItemImgDO updateObj = InspectItemImgConvert.INSTANCE.convert(updateReqVO);
        inspectItemImgMapper.updateById(updateObj);
    }

    @Override
    public void deleteInspectItemImg(Long id) {
        // 校验存在
        this.validateInspectItemImgExists(id);
        // 删除
        inspectItemImgMapper.deleteById(id);
    }

    private void validateInspectItemImgExists(Long id) {
        if (inspectItemImgMapper.selectById(id) == null) {
            throw exception(INSPECT_ITEM_IMG_NOT_EXISTS);
        }
    }

    @Override
    public InspectItemImgDO getInspectItemImg(Long id) {
        return inspectItemImgMapper.selectById(id);
    }

    @Override
    public List<InspectItemImgDO> getInspectItemImgList(Collection<Long> ids) {
        return inspectItemImgMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<InspectItemImgDO> getInspectItemImgPage(InspectItemImgPageReqVO pageReqVO) {
        return inspectItemImgMapper.selectPage(pageReqVO);
    }

    @Override
    public List<InspectItemImgDO> getInspectItemImgList(InspectItemImgExportReqVO exportReqVO) {
        return inspectItemImgMapper.selectList(exportReqVO);
    }

}
